package cn.zjj.fallbackfactory;

import cn.zjj.domain.User;
import cn.zjj.feignClient.UserFeignClient;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class UserFallFactory implements FallbackFactory<UserFeignClient> {
    @Override
    public UserFeignClient create(Throwable throwable) {
        return new UserFeignClient() {
            @Override
            public User selectById(Long id) {
                return new User(-1L,"发生熔断",-1,"已经下线此服务器");
            }

            @Override
            public List<User> select() {
                User user = new User(-2L, "发生熔断", -2, "已经下线此服务器");
                List<User> list = new ArrayList<>();
                list.add(user);
                return list;
            }
        };
    }
}
